package com.sesame.user.controller;

import com.sesame.defin.AbstractController;
import com.sesame.defin.Response;
import com.sesame.entity.User;
import com.sesame.user.service.UserService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CommonsLog
@RestController
@RequestMapping("/user")
public class UserController extends AbstractController {

    @Autowired
    UserService userService;

    /**
     * http://localhost:8091/user/list
     */
    @RequestMapping("/list")
    public Response list() {
       List<User> list = userService.list();
        return returnSuccess(list);
    }

    @RequestMapping("/updateCacheDetail")
    public Response updateCacheDetail(String id) {
        User user = userService.updateCacheDetail(id);
        return returnSuccess(user);
    }

    /**
     * http://localhost:8091/user/detail?id=1
     */
    @RequestMapping("/detail")
    public Response detail(String id) {
        log.info(">>>>>>进入 controller detail id:"+id);
        User user = userService.detailById(id);
        return returnSuccess(user);
    }
    /**
     * http://localhost:8091/user/update?id=1&name=a
     */
    @RequestMapping("/update")
    public Response update(String id,String name) {
        userService.update(id,name);
        return returnSuccess();
    }
    /**
     * http://localhost:8091/user/update?name=aa
     */
    @RequestMapping("/add")
    public Response add(String name) {
        userService.add(name);
        return returnSuccess();
    }
    /**
     * http://localhost:8091/user/del?id=1
     */
    @RequestMapping("/del")
    public Response del(String id) {
        userService.del(id);
        return returnSuccess();
    }


}
